package com.springboot.cloud.demos.feign.rest;

import com.springboot.cloud.common.core.entity.vo.Result;
import com.springboot.cloud.demos.entity.form.UserCouponForm;
import com.springboot.cloud.demos.entity.form.UserCouponQueryForm;
import com.springboot.cloud.demos.entity.param.UserCouponQueryParam;
import com.springboot.cloud.demos.entity.po.UserCoupon;
import com.springboot.cloud.demos.entity.po.User;
import com.springboot.cloud.demos.feign.service.UserCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
public class UserCouponController extends BaseController {

    @Autowired
    private UserCouponService userCouponService;

    @RequestMapping(value = "/userCoupon", method = RequestMethod.POST)
    public Result save(HttpServletRequest request, @RequestBody UserCouponForm userCoupon) {
        User user = getUser(request);
        userCoupon.setUserId(user.getId());
        return userCouponService.add(userCoupon);
    }

    @RequestMapping(value = "/userCoupon", method = RequestMethod.PUT)
    public Result update(HttpServletRequest request, @RequestBody UserCouponForm userCoupon) {
        User user = getUser(request);
        return userCouponService.update(userCoupon);
    }

    @RequestMapping(value = "/userCoupon/{userId}", method = RequestMethod.GET)
    public Result get(@PathVariable String userId) {
        UserCouponQueryParam param = new UserCouponQueryParam();
        param.setUserId(userId);
        return userCouponService.conditions(param);
    }

    @RequestMapping(value = "/userCoupon/getUserCoupon", method = RequestMethod.GET)
    public Result getUserCoupon(String userId) {
        UserCouponQueryParam param = new UserCouponQueryParam();
        param.setUserId(userId);
        return userCouponService.conditions(param);
    }
}
